<!--专家指导左边问答列表组件-->
<template>
    <div class="goods-box3">
        <div class="search">
            <div style="display: flex;height: 35px;line-height: 35px;padding-left: 10px;">
                <el-input v-model="searchKeys" maxlength="100" clearable style="width:290px;" />
                <img src="@/assets/img/search.png" @click="handleSearch" class="search-icon" />
                <el-button v-show="searchKeys != ''"
                    style="width: 80px;height:35px;line-height: 35px;margin-left: 10px;" @click="backHandle">
                    <el-icon>
                        <Close />
                    </el-icon>取 消
                </el-button>
            </div>
            <div style="color:#696969;font-size:12px;font-style:normal;text-align: left;padding-left: 10px;">
                热门搜索：
                <a class="tag-item" @click="handleTopicDetail('苹果果树种植方法')">苹果果树种植方法 </a> 
                <a class="tag-item" @click="handleTopicDetail('新疆哈密瓜甜度控制')">新疆哈密瓜甜度控制</a>
                <a class="tag-item" @click="handleTopicDetail('玉米苗灌溉')">玉米苗灌溉</a>
            </div>
        </div>
        <div class="goods" v-for="(item, index) in cquestions" :key="index" @click="detailsClick(item.id)">
            <div class="info">
                <p class="content">
                    <i class="question-text" style="" v-if="item.status == 0">[问]&nbsp;&nbsp;</i>
                    <i class="question-text" v-else>[答]&nbsp;&nbsp;</i>
                    <span class="question-content">{{ item.title }}</span>
                </p>
                <div class="person-contents">
                    <span>提问者：{{ item.questioner }}</span>&nbsp;&nbsp;&nbsp;
                    <span>专家：{{ item.expertName }}</span>
                </div>
            </div>
        </div>
       

        <!-- 分页 -->
        <div v-show="null !== cquestions && cquestions.length > 0"
            style="width: 100%;display:flex;justify-content: center;margin-top: 10px;">
            <el-pagination background layout="prev, pager, next" :page-size="pageSize" :total="total"
                @current-change="handleCurrentChange" />
        </div>
    </div>
</template>

<script setup>
import { defineProps, ref } from 'vue';
import router from '@/router'
import { defineEmits } from 'vue';

const emit = defineEmits(['handleSearch','refresh']);
// 接收父组件传过来的数据
const props = defineProps({
    cquestions: {
        type: Array,
    },
    total:{
        type: Number
    },
    pageSize:{
        type: Number
    },
    url:{
        type: String
    }
})

//搜索
const searchKeys = ref('');

//搜索
const handleSearch = () => {
    emit('handleSearch', searchKeys.value)
}

//关键字搜索
const handleTopicDetail = (val) => {
    searchKeys.value = val
    handleSearch()
}

//返回
const backHandle = () => {
    searchKeys.value = ''
    //调用父类的方法
    emit('refresh')
}

//详情
const detailsClick = (id) => {
    router.push(`/index/guide_details/${id}`).catch((err) => err);
}

//分页
const handleCurrentChange = (val) => {
    emit('pageClick', val)
}

</script>

<style lang="scss" scoped>
.search {
    width: 100%;
    background-color: white;
    line-height: 35px;
    padding-top: 10px;
    padding-left: 10px;

    .tag-item {
        margin-right: 10px;
        cursor: pointer;
        color: blue;
    }

    .search-icon {
        position: relative;
        left: -2px;
        cursor: pointer;
    }
}

.goods-box3 {
    width: 730px;
    padding-bottom: 30px;
    background-color: white;
    .goods {
        text-align: left;
        width: 730px;
        min-height: 80px;
        padding: 10px 20px;
        background-color: white;
        border-radius: 0px;
        border-bottom: 1px solid #f2f2f2;
        color: rgb(25, 21, 5);
        display: flex;
        justify-content: center;

        .info {
            width: 685px;

            .title {
                /*超出的部分隐藏*/
                overflow: hidden;
                /*文字用省略号替代超出的部分*/
                text-overflow: ellipsis;
                /*弹性伸缩盒子模型显示*/
                display: -webkit-box;
                /*限制在一个块元素显示文本的行数*/
                -webkit-line-clamp: 1;
                /*设置或检索伸缩盒对象的子元素排列方式*/
                -webkit-box-orient: vertical;
            }

            .content {
                width: 680px;
                line-height: 20px;
                display: flex;
                flex-direction: row;
                justify-content: flex-start;
                align-items: center;
                /*超出的部分隐藏*/
                overflow: hidden;
                /*文字用省略号替代超出的部分*/
                text-overflow: ellipsis;
                /*弹性伸缩盒子模型显示*/
                display: -webkit-box;
                /*限制在一个块元素显示文本的行数*/
                -webkit-line-clamp: 7;
                /*设置或检索伸缩盒对象的子元素排列方式*/
                -webkit-box-orient: vertical;

                .question-text {
                    color: #666;
                    font-style: normal;
                }
            }

            .person-contents {
                display: flex;
                flex-direction: row;
                justify-content: flex-end;
                font-size: 12px;
                color: #666;
            }

            .price {
                font-size: 15px;
                font-weight: bold;
                display: block;
                color: red;
            }
        }
    }

    .goods:hover {
        background-color: #f2f2f2;
    }
}

.marginR5 {
    margin-right: 5px;
}

.question-content {
    cursor: pointer;

    &:hover {
        text-decoration: underline;
        color: #035D1C;
    }
}

.search .el-input--suffix .el-input__inner {
    height: 35px;
    line-height: 35px;
}
</style>